import allConst from "@/Json.js"
import uniIcon from '@/components/uni-icon/uni-icon.vue';
import uniCalendar from '@/components/uni-calendar/uni-calendar.vue';
import * as Api from '@/syApis/syAddOrder/syaddApis.js';
import goodModel from '@/components/ShowModl.vue';
import addOrderList from '@/components/selectGoodsItemBrach/selectGoodsItemBrach';
import settingOption from "@/components/settingOption/settingOption.vue";
import selectSimple from '@/components/selectGoodsItem/selectSimple';
import * as rules from "@/common/barcodeRules.js"
export default {
	data() {
		return {
			isShowGoodsType: 0,
			typeName: "全部分类",
			date: '',
			timeData: {
				clockinfo: '',
				date: '',
				fulldate: '',
				lunar: '',
				month: '',
				range: '',
				year: ''
			},
			munelist: [{
				title: '单据信息',
			}, {
				title: '商品明细'
			}],
			TabCur: 0,
			scrollLeft: 0,
			//供应商picker索引
			index: -1,
			//业务员picker索引
			index1: -1,
			//
			index2: -1,
			index3: -1,
			//是否赠品picker索引
			index5: -1,
			picker: ['批发客户', '零售客户', '批发价1客户'],
			picker1: ['张三', '李四', '王五'],
			picker2: [],
			picker3: [],
			index4: -1,
			list: [{
				index: 0,
				name: "单据信息"
			}],
			modalName: '',
			unitslist: [{
				unit: "件"
			}, {
				unit: "箱"
			}],
			unitselected: '',
			BillNo: "",
			//单据类型
			BillType: 1,
			IsAdd: 0,
			BillDate: "",
			//订单商品
			OrderGoodsList: [],
			//当前选择的商品
			NowSelectGoods: {},
			//商品数量
			GoodsQty: "",
			//商品折扣
			GoodsDiscount: "",
			//商品备注
			GoodsRemark: "",
			//商品库存
			GoodsStorm: "",
			//调入仓库的列表
			StoreInList: [],
			//业务员的列表
			OperatorList: [],
			//供应商的列表
			ClientList: [],
			//制单人
			CreateName: uni.getStorageSync("UserName"),
			//税率
			Tax: "",
			//商品列表查看更多标识
			selectLookMore: -1,
			//按下屏幕的时间
			endTime: 0,
			//计算点击的时间
			touchTime: 0,
			//扫码多商品列表
			scanGoodList: [{
				name: "标题"
			}],
			//当前多商品选择的索引
			current: -1,
			//多规格商品弹框
			isShowScanModel: false,
			//选择了商品
			isSelectGood: false,
			//是否引用源单
			isYy: false,
			//搜索条件
			searchKey: "",
			//单据类型
			BillName: "采购订单",
			//单据类型编号
			BillType: 1,
			//本次付款
			CollectAmount: 0,
			//抹零金额
			NoSmallAmount: 0,
			//生产日期
			ProductionDate: "",
			//有效日期
			ValidityDate: "",
			//配出仓库分支
			pcChildName: "",
			//配入仓库分支
			prChildName: "",
			//扫码多商品弹窗标题
			scanGoodTitle: "选择商品",
			//是否显示更多表头信息
			isHeadShowMore: false,
			//查看更多提示
			TbHeaderMore: "查看更多",
			//查看更多状态
			isLookHeaderMore: false,
			//是否是修改单据
			isChange: false,
			//当前选择的业务员条目
			SelectOptionsObj: {
				OperatorName: "",
				OperatorID: ""
			},
			//当前选择的调入仓库条目
			SelectInStoreObj: {
				StoreName: "",
				StoreID: "",
				BranchName: "",
				BranchID: ""
			},
			//当前选择的调出仓库条目
			SelectOutStoreObj: {
				StoreName: "",
				StoreID: "",
				BranchName: "",
				BranchID: ""
			},
			//调入仓库名称搜索
			SearchInStoreName: "",
			//调出仓库名称搜索
			SearchOutStoreName: "",
			//业务员搜索
			SearchOptionName: "",
			isShowTip: false,
			//调出仓库
			StoreOutList: [],
			//当前单据编号
			BillID: "",
			TempOptionList: [],
			TempStoreInList: [],
			TempStoreOutList: [],
			//单据权限
			isUserRoot: {},
			unLoadimg: '../../static/unUplad.png',
			//本地保存的设置数组
			cgSettingLocation: {},
			// 打印设置弹出框
			modalNames: null,
			//打印份数
			printNum: 1,
			//打印机编号
			printCode: 0,
			allConstUrl: allConst.imgurlHeader,
			isChangeShow: false,
			barCodeRelus: {
				Rule_Separate: "",
				Rule_Bar: "",
				Rule_Code: "",
				Rule_Num: "",
				Rule_Num_Demical: "",
				Rule_Price: "",
				Rule_Price_Demical: "",
				Rule_SN: "",
				Rule_BatchNo: "",
				Rule_Color: "",
				Rule_Size: "",
				Separate_IsEnable: "",
				BarRule_All_Length: "",
				BarRule_CutBar_Start: "",
				BarRule_CutBar_End: "",
				BarRule_CutCode_Start: "",
				BarRule_CutCode_End: "",
				BarRule_CutNum_Start: "",
				BarRule_CutNum_End: "",
				BarRule_CutNum_Demical: "",
				BarRule_CutPrice_Start: "",
				BarRule_CutPrice_End: "",
				BarRule_CutPrice_Demical: "",
				BarRule_CutSN_Start: "",
				BarRule_CutSN_End: "",
				BarRule_CutBatchNo_Start: "",
				BarRule_CutBatchNo_End: "",
				BarRule_CutColor_Start: "",
				BarRule_CutColor_End: "",
				BarRule_CutSize_Start: "",
				BarRule_CutSize_End: "",
				Cut_IsEnable: "",
				Ignore_Befor: "",
				Ignore_After: ""
			},
			//条码分割数组
			barRulesList: [],
			//是否启用分隔规则0 分割规则1 2不启用
			SeparateIsEnable: 0,
			isBillCheckQx: false,
			SelectClientObj: {
				ClientID: "",
				ClientName: ""
			},
			isGetPriceFollowMessage: [],
			AddGoodsTempList: [],
			isScanGoodMessage: [],
			tempScanGoodList: [],
			isSearch: false,
			isHide: false
		}
	},
	components: {
		uniCalendar,
		uniIcon,
		goodModel,
		addOrderList,
		settingOption,
		selectSimple
	},
	onLoad(options) {
		var _this = this;
		this.BillName = options.BillName;
		this.getBillTime();
		console.log(options.BillName);
		this.BillType = options.BillName == '配送申请单' ? '14' : options.BillName == '配送出库单' ? '15' : '16';
		// setTimeout(() => {
		// 	this.showCalendar = true
		// }, 350);
		this.GetOperatorMessage();
		this.GetStoreMessage();
		let PDA_Module_Android = uni.getStorageSync("PDA_Module_Android"); //获取单据权限
		PDA_Module_Android = JSON.parse(PDA_Module_Android);
		var that = this;
		PDA_Module_Android.forEach((item, index) => {
			if (this.BillName == item.ModuleName) {
				that.isUserRoot = item;
			}
		});
		if (options.type == 1) {
			let oldOrder = JSON.parse(options.oldOrder);
			this.oldOrder = oldOrder;
			try{
				this.BillNo = oldOrder.BillNo;
				this.BillID = oldOrder.BillID;
				this.timeData.fulldate = oldOrder.BillTime;
				this.SelectInStoreObj.StoreName = oldOrder.stockName2;
				this.SelectInStoreObj.StoreID = oldOrder.StoreID2;
				this.SelectInStoreObj.BranchName = oldOrder.BranchName2;
				this.SelectOutStoreObj.StoreName = oldOrder.stockName;
				this.SelectOutStoreObj.BranchName = oldOrder.BranchName;
				this.SelectOutStoreObj.StoreID = oldOrder.StoreID;
				this.SelectOptionsObj.OperatorID = oldOrder.EmpID;
				this.SelectOptionsObj.OperatorName = oldOrder.EName;
				this.CollectAmount = oldOrder.CollectAmount;
				this.NoSmallAmount = oldOrder.NoSmallAmount;
				this.GoodsRemark = oldOrder.Comment;
				this.CreateName = oldOrder.OpenName;
				console.log(this.CreateName );
			}catch(e){
				console.log(e);
			}
			
			// this.startTime = oldOrder.startTime.split(" ")[0];
			// this.endTime = oldOrder.EndTime.split(" ")[0];
			this.getBillDetail(oldOrder.BillID);
			this.isChange = true;
			console.log(this.isChange);
		} else {
			this.isChange = false;
		}
		let barCodeRelus = uni.getStorageSync("BarCode", "");
		if (barCodeRelus != "") {
			this.barCodeRelus = JSON.parse(barCodeRelus);;
		}
		uni.setNavigationBarTitle({
			title: options.BillName
		})
		let SystemSettingInfo = uni.getStorageSync("SystemSettingInfo", ""); //存储系统设置
		SystemSettingInfo = JSON.parse(SystemSettingInfo);
		SystemSettingInfo.forEach((item, index) => {
			if (item.SystemName == '单据是否直接审核') {
				if (item.Value == "1") {
					that.isBillCheckQx = true;
				}
				// console.log(item.Value);
			}
		});
		
		try{
			Api.registerReciver(function(barcode) {
				_this.searchKey = barcode;
				_this.search(false);
			});
		}catch(e){
			//TODO handle the exception
		}

	},
	onHide(){
		this.isHide = true;
	},
	onPageScroll(e) {
		if (e.scrollTop > 400) {
			this.isShowTip = true;
		} else {
			this.isShowTip = false;
		}
	},
	computed: {
		goodAllAmount() {
			var Ammount = 0;
			var that = this;
			this.OrderGoodsList.forEach(item => {
				Ammount += that.compuTaxMoney(item);
			});
			return Math.round(Ammount * 100) / 100;
		},
		OrderGoodsListLength() {
			var AllCount = 0;
			var that = this;
			this.OrderGoodsList.forEach(item => {
				AllCount += parseFloat(item.Qty);
			});
			return AllCount;
		}
	},
	onPageScroll(e) {
		if (e.scrollTop > 400) {
			this.isShowTip = true;
		} else {
			this.isShowTip = false;
		}
	},
	watch: {
		//判断添加获取价格方案是否全部完成
		isGetPriceFollowMessage(newVal) {
			console.log(newVal.length);
			var that = this;
			if (newVal.length == this.AddGoodsTempList.length && newVal.length != 0) {
				setTimeout(function() {
					uni.hideLoading();
					that.isSearch = false;
					if (that.AddGoodsTempList.length > 0) {
						that.isInOrderList(that.AddGoodsTempList);
					}

				}, 200);
			}
		}
		// ,
		//判断扫码数据获取价格方案是否全部完成
		// isScanGoodMessage(newVal) {
		// 	var that = this;
		// 	if (newVal.length == this.tempScanGoodList.length && newVal.length != 0) {
		// 		setTimeout(function() {
		// 			uni.hideLoading();
		// 			let data = {
		// 				data: {
		// 					ResultMsg: that.tempScanGoodList
		// 				}
		// 			}

		// 			that.scanGoodList = that.pullBarCodeGoods(data).data.ResultMsg;
		// 			if (that.scanGoodList.length == 1) {
		// 				that.selectGoodsList(0);
		// 			} else {
		// 				if (that.scanGoodList.length > 0) {
		// 					that.modalName = "StoreScanGoodModal";
		// 				}

		// 			}
		// 		}, 500);
		// 	}
		// }
	},
	onShow() {
		this.$eventHub.$off('AddChangeBill');
		this.$eventHub.$off('fires');
		this.$eventHub.$off('fireData');
		this.isHide  = false;
		this.isSearch = false;
	},
	onUnload(){
		console.log("页面卸载");
		try {
			Api.unRegisterReciver();
		} catch (e) {
			//TODO handle the exception
		}
		
	},
	methods: {
		getBillTime(){
			let date = new Date();
			var month = date.getMonth() + 1;
			if (month < 10) {
				month = "0" + month
			}
			var day = date.getDate();
			if (day < 10) {
				day = "0" + day;
			}
			this.BillDate = date.getFullYear() + "-" + month + "-" + day;
			
		},
		xpDy() {
			if (this.isChange) {
				// console.log(this.$refs.settingOption._data);
				// this.$refs.settingOption._data.modalPrintName = "printSetting";
				// this.modalNames = 
				console.log("小票打印ssssss");
				let item = {
					Save_M_Data_Json: this.oldOrder,
					Save_D_Data_Json: this.OrderGoodsList
				}
				console.log(item);
				let mac_address = uni.getStorageSync("bluetoothName", "");
				if (mac_address == "") {
					Api.showTip("请先连接打印机");
					return;
				}
				rules.print(mac_address, item, this.BillType);

			} else {
				Api.showTip("请先查询单据");
			}
		},
		//判断加入的商品是否存在
		isInOrderList(GoodsItem) {
			let state = this.cgSettingLocation.onlyAddNum[0].state;
			let NewGoodListTemp = [];
			this.OrderGoodsList.forEach((item, index) => {
				NewGoodListTemp.push(item);
			});
			// GoodsItem = tempList;
			var unAddGood = [];
			GoodsItem.forEach((item, index) => {
				let items = this.IsInOrderList(item, state);
				if (items.isUnAdd) {
					unAddGood.push(index);
				} else {
					if (!items.isIn) {
						NewGoodListTemp.push(item);
					}
				}
			});
			if (unAddGood.length > 0) {
				Api.showTip("批号商品批号不能为空");
			}
			// return;
			// return;
			this.OrderGoodsList = NewGoodListTemp;
			this.isSearch = false;
			this.searchKey = "";
		},
		//获取价格方案
		pullGoodsInfo(GoodsItem) {
			console.log(GoodsItem);
			this.AddGoodsTempList = GoodsItem;
			var that = this;
			for (var i in this.AddGoodsTempList) {
				this.XH_Get_PriceFollowMessage(this.AddGoodsTempList[i], i, function(res, index) {
					if (!that.AddGoodsTempList[index].isSet) {
						that.AddGoodsTempList[index].Price = res;
						that.AddGoodsTempList[index].DiscountPrice = that.DiscountPrice(that.AddGoodsTempList[index]);
						that.AddGoodsTempList[index].Amount = that.Amount(that.AddGoodsTempList[index]);
					}

				});
			}

		},
		//价格跟踪
		XH_Get_PriceFollowMessage: async function(priceItem, Filter = "", success, isScan = false) {
			console.log(this.BillName);
			var that = this;
			let data = {
				GoodsID: priceItem.GoodsID,
				UnitID: priceItem.UnitID,
				BillName: this.BillName,
				URate: priceItem.urate,
				ClientID: this.SelectClientObj.ClientID || ""
			}
			Api.XH_Get_PriceFollowMessage(data, function(res) {
				// console.log(Filter);
				if (isScan) {
					that.isScanGoodMessage.push(Filter);
				} else {
					that.isGetPriceFollowMessage.push(Filter);
				}
				if (res.state) {
					if (res.data.ResultMsg != "") {
						// that.PriceList = res.data.ResultMsg;
						// priceItem.Price = that.PriceList[0].Price;
						success(res.data.ResultMsg[0].Price, Filter);
					} else if (res.data.ErrorMsg == '获取登录信息失败') {
						Api.showTip(res.data.ErrorMsg);
					} else {
						Api.showTip(res.data.ErrorMsg);
					}

				} else {

				}
			});
		},
		defaultSetting() {
			this.clearAll();
			/**获取默认设置**/
			let settingList = uni.getStorageSync("settingList", "");
			if (settingList != "") {
				settingList = JSON.parse(settingList);
				// console.log(this.settingList);
				settingList.forEach((item, index) => {
					//如果是调拨单则不赋值供应商或客户
					if (this.BillType != 14 && this.BillType != 15 && this.BillType != 16) {
						if (item.Default_Name == '供应商' && this.BillType != 4) {
							this.SelectClientObj.ClientName = item.Default_Value;
							this.SelectClientObj.ClientID = item.Default_ID;
						} else if (item.Default_Name == '客户' && this.BillType == 4) {
							this.SelectClientObj.ClientName = item.Default_Value;
							this.SelectClientObj.ClientID = item.Default_ID;
						}
					}
					if (item.Default_Name == "业务员") {
						this.SelectOptionsObj.OperatorName = item.Default_Value;
						this.SelectOptionsObj.OperatorID = item.Default_ID;
					}
					if (item.Default_Name == '仓库') {
						// this.SelectInStoreObj.StoreName = item.Default_Value;
						// this.SelectInStoreObj.StoreID = item.Default_ID;
						// this.SelectOutStoreObj.StoreID = item.Default_ID;
						// this.SelectOutStoreObj.StoreName = item.Default_Value;
						this.TempStoreOutList.forEach(($item, $index) => {
							if ($item.StoreID == item.Default_ID) {
								this.SelectOutStoreObj = $item;
								// return;
							}
						});
					}
				});
			}
		},
		//切换商品列表
		changeSelectShow() {
			this.isChangeShow = !this.isChangeShow;
		},
		onNavigationBarButtonTap(e) {
			const index = e.index;
			// console.log(index);
			if (index == 0) {
				this.modalName = 'DrawerModalR';
			}
		},
		changeSetting(e) {
			this.cgSettingLocation = e.detail;
			this.isChangeShow = this.cgSettingLocation.GoodShowSimpleInfo[0].state;
		},
		DateChange(e) {
			this.BillDate = e.detail.value;
		},
		DateChangePro(e) {
			this.ProductionDate.fulldate = e.detail.value;
		},
		DateChangeVal(e) {
			this.ValidityDate = e.detail.value;
		},
		//返回顶部
		scrollTop() {
			uni.pageScrollTo({
				scrollTop: 0,
				duration: 0
			});
		},
		filterInStore(e) {
			let value = e.detail.value;
			this.TempStoreInList = [];
			var that = this;
			this.StoreInList.forEach((item, index) => {
				if (item.StoreName.indexOf(value) > -1) {
					that.TempStoreInList.push(item);
				}
			});
		},
		filterOutStore(e) {
			let value = e.detail.value;
			this.TempStoreOutList = [];
			var that = this;
			this.StoreOutList.forEach((item, index) => {
				if (item.StoreName.indexOf(value) > -1) {
					that.TempStoreOutList.push(item);
				}
			});
		},
		filterOption(e) {
			let value = e.detail.value;
			this.TempOptionList = [];
			var that = this;
			this.OperatorList.forEach((item, index) => {
				if (item.OperatorName.indexOf(value) > -1) {
					that.TempOptionList.push(item);
				}
			});
		},
		//获取单据明细
		getBillDetail(BillNo) {
			this.BillID = BillNo;
			let data = {
				BillID: BillNo,
				BillType: this.BillType
			};
			var that = this;
			Api.SelectBillDetail(data, function(res) {
				if (res.state) {
					if (res.data.ErrorMsg == '获取登录信息失败') {

					} else if (res.data.ErrorMsg != '') {
						Api.showTip(res.data.ErrorMsg);
					} else {
						res.data.ResultMsg.forEach((item, index) => {
							res.data.ResultMsg[index].DiscountPrice = that.DiscountPrice(item);
							res.data.ResultMsg[index].Amount = that.Amount(item);
							res.data.ResultMsg[index].stockqty = item.stock_qty;
							res.data.ResultMsg[index].IsGift = item.IsGift ? 1 : 0;
							res.data.ResultMsg[index].urate = item.URate;
							res.data.ResultMsg[index].ProductionDate = item.ProductionDate.split(" ")[0];
							res.data.ResultMsg[index].validityDate = item.validityDate.split(" ")[0];
							if (res.data.ResultMsg[index].Goods_Image_Path1 == '' || typeof res.data.ResultMsg[index].Goods_Image_Path1 ==
								'undefined') {
								res.data.ResultMsg[index].Goods_Image_Path1 = that.unLoadimg;
							} else {
								res.data.ResultMsg[index].Goods_Image_Path1 = allConst.pictureUrl + res.data.ResultMsg[index].Goods_Image_Path1;
							}
						})
						that.OrderGoodsList = res.data.ResultMsg;

					}
				}
			})
		},
		getVarDate(days) {
			console.log(days);
			let date = new Date();
			let time = date.getTime() + days * 24 * 60 * 60 * 1000;
			let AddDate = new Date(time);
			console.log(AddDate.getFullYear());
			// let date = new Date();
			var month = AddDate.getMonth() + 1;
			if (month < 10) {
				month = "0" + month
			}
			var day = AddDate.getDate();
			if (day < 10) {
				day = "0" + day;
			}
			return AddDate.getFullYear() + "-" + month + "-" + day;
		},
		DiscountPrice(item) {
			return parseFloat(item.Price) * (parseFloat(item.Discount) / 100) * (1 + parseFloat(
				item.Tax) / 100);
		},
		//计算总价
		Amount(item) {
			return parseFloat(item.Price) * parseFloat(item.Qty) * (parseFloat(item.Discount) / 100) * (1 + parseFloat(
				item.Tax) / 100);
			// return  PFPrice;
		},
		lookOrder() {
			// this.AddChangeBill();
			// if(this.BillType==2||this.BillType==3||this.BillType)
			if(this.isChange){
				uni.redirectTo({
					url: "../selPurchasePs/selPurchase?BillName=" + this.BillName
				})
			}else{
				uni.navigateTo({
					url: "../selPurchasePs/selPurchase?BillName=" + this.BillName
				})
			}
			
		},
		AddChangeBill() {
			var _this = this;
			//当前选择的商品的临时列表
			// var NewGoodListTemp = this.OrderGoodsList;
			this.$eventHub.$on('AddChangeBill', function(data) {
				console.log("12111");
				// let GoodsItem = JSON.parse(data);	
				// // console.log(_this.OrderGoodsList);
				// _this.pullGoodsInfo(GoodsItem);
				let oldOrder = JSON.parse(data);
				// let oldOrder = JSON.parse(options.oldOrder);
				_this.oldOrder = oldOrder;
				_this.BillNo = oldOrder.BillNo;
				_this.BillID = oldOrder.BillID;
				_this.timeData.fulldate = oldOrder.BillTime;
				_this.CreateName = oldOrder.CreateName;
				// this.SelectClientObj.ClientName = oldOrder.ClientName;
				_this.SelectInStoreObj.StoreName = oldOrder.stockName2;
				_this.SelectInStoreObj.StoreID = oldOrder.StoreID2;
				_this.SelectInStoreObj.BranchName = oldOrder.BranchName2;
				_this.SelectOutStoreObj.StoreName = oldOrder.stockName;
				_this.SelectOutStoreObj.BranchName = oldOrder.BranchName;
				_this.SelectOutStoreObj.StoreID = oldOrder.StoreID;
				_this.SelectOptionsObj.OperatorID = oldOrder.EmpID;
				_this.SelectOptionsObj.OperatorName = oldOrder.EName;
				// this.SelectClientObj.ClientName = oldOrder.BName;
				// this.SelectClientObj.ClientID = oldOrder.ClientID;
				_this.CollectAmount = oldOrder.CollectAmount;
				_this.NoSmallAmount = oldOrder.NoSmallAmount;
				_this.Comment = oldOrder.Comment;
				// this.startTime = oldOrder.startTime.split(" ")[0];
				// this.endTime = oldOrder.EndTime.split(" ")[0];
				_this.getBillDetail(oldOrder.BillID);
				_this.isChange = true;
				_this.$eventHub.$off('AddChangeBill');
			});
		},
		//显示弹框
		showModal(e) {
			this.modalName = e.currentTarget.dataset.target
		},
		//选择仓库
		selectStore(index) {
			this.SelectStoreObj = this.StoreList[index];
			this.modalName = null;
		},
		hideModal() {
			this.modalName = null;
		},
		//返回顶部
		scrollTop() {
			uni.pageScrollTo({
				scrollTop: 0
			});
		},
		//清空单据
		sureClear() {
			var that = this;
			uni.showModal({
				title: "是否清空单据",
				content: "清空后不可恢复,是否确认",
				success(res) {
					if (res.confirm) {
						that.clearAll();
					}
				}
			})
		},
		//清空单据
		clearAll(isBill=false) {
			
			this.BillNo = "";
			//当前选择的业务员条目
			this.OrderGoodsList = [];
			this.SelectOptionsObj = {
				OperatorID: "",
				OperatorName: ""
			};
			this.GoodsRemark = "";
			//当前选择的调入仓库条目
			this.SelectInStoreObj = {
					StoreName: "",
					StoreID: "",
					BranchName: "",
					BranchID: ""
				},
				//当前选择的调出仓库条目
				this.SelectOutStoreObj = {
					StoreName: "",
					StoreID: "",
					BranchName: "",
					BranchID: ""
				},
				this.BillNo = "";
				if(isBill){
					
						this.GetNewOrderNo(false);
					
				}
				this.isChange = false;
		},
		//删除选择的商品
		deleteSelectGood(e) {
			var _this = this;
			let index = e.currentTarget.detail.deleteIndex;
			Api.showConfirm("是否删除此商品", function(state) {
				if (state) {
					_this.removeItem(index);
				} else {

				}
			})
		},
		//调入仓库搜索
		searchInStore() {
			if (this.SearchInStoreName != "") {
				let Filter = "StoreName like '%" + this.SearchInStoreName + "%'";
				this.GetStoreMessage(Filter, 0);
			} else {
				this.GetStoreMessage();
			}
		},
		//调出仓库搜索
		searchOutStore() {
			if (this.SearchOutStoreName != "") {
				let Filter = "StoreName like '%" + this.SearchOutStoreName + "%'";
				this.GetStoreMessage(Filter, 1);
			} else {
				this.GetStoreMessage();
			}
		},
		//选择业务员
		selectOptions(index) {
			this.SelectOptionsObj = this.OperatorList[index];
			this.modalName = null;
		},
		//搜索业务员
		searchOption() {
			if (this.searchOption != '') {
				let Filter = "OperatorName like '%" + this.SearchOptionName + "%'";
				this.GetOperatorMessage(Filter);
			} else {
				this.GetOperatorMessage();
			}
		},
		//调入仓库选择
		selectInStore(index) {
			this.SelectInStoreObj = this.StoreInList[index];
			this.modalName = null;
		},
		//调出仓库选择
		selectOutStore(index) {
			this.SelectOutStoreObj = this.StoreOutList[index];
			this.modalName = null;
		},
		//查看表头更多信息
		lookHeaderMore() {
			this.isLookHeaderMore = !this.isLookHeaderMore;
			if (this.isLookHeaderMore) {
				this.TbHeaderMore = "收起更多"
			} else {
				this.TbHeaderMore = "查看更多"
			}
		},
		//选择扫码商品
		choosesGoods(index) {
			this.NowSelectGoods = this.scanGoodList[index];
			console.log(this.NowSelectGoods);
			this.isShowScanModel = false;
			this.isSelectGood = true;
		},
		radioChange(evt) {
			this.NowSelectGoods = this.scanGoodList[evt.target.value];
			console.log(this.NowSelectGoods);
			this.isShowScanModel = false;
			this.isSelectGood = true;
		},
		search(flag = true) {
			//如果不是扫描头
			// if (flag) {

			// } else {
			//如果是开启了快速扫描
			if (this.cgSettingLocation.QuiteAddGoodInfo[0].state) {
				flag = false;
			} else {
				flag = true;
			}

			// }
			if (this.SelectOutStoreObj.StoreID == "") {
				Api.showTip("请选择调入仓库");
				return;
			}
			if(this.isSearch){
				Api.showTip("数据处理中,请稍后");
				return;
			}
			if(this.isHide){
				return;
			}
			this.searchKey  =this.searchKey.replace(/^\s+|\s+$/g,"");
			this.isScanGoodMessage = [];
			this.isGetPriceFollowMessage = [];
			let finalObj = rules.getRulesStr(this.cgSettingLocation.BarcodeRule[0].state,
				this.barCodeRelus, this.searchKey);
			console.log(finalObj);
			//判断启用的条码规则
			this.SeparateIsEnable = finalObj.SeparateIsEnable;
			this.barRulesList = finalObj.barRulesList;
			// this.searchKey = ;
			this.GetBarcodeGoodsMessageModel(finalObj.searchKey, flag);
		},
		//扫码获取商品
		tel: function() {
			// Api.showTip("网页端暂不支持此功能");
			// return;
			this.current = -1;
			// 调起条码扫描
			var _this = this;
			uni.scanCode({
				scanType: 'barCode',
				success: function(res) {
					_this.isGetPriceFollowMessage = [];
					var flag = true;
					if (_this.cgSettingLocation.QuiteAddGoodInfo[0].state) {
						flag = false;
					} else {
						flag = true;
					}
					_this.GetBarcodeGoodsMessageModel(res.result,flag);
					console.log('条码类型：' + res.scanType);
					console.log('条码内容：' + res.result);
				},
				fail(e) {
					console.log(e);
				}
			});
		},
		//通过条码扫描商品
		GetBarcodeGoodsMessageModel(barcode, flag = true) {
			// uni.showLoading({
			// 	title: "加载中...",
			// 		mask:false
			// })
			this.isSearch = true;
			let Model = "";
			if (this.cgSettingLocation.BarLike[0].state) {
				Model = "%like"
			} else if (this.cgSettingLocation.BarLike[1].state) {
				Model = "like%"
			} else if (this.cgSettingLocation.BarLike[2].state) {
				Model = "like"
			} else {
				Model = "="
			}
			let data = {
				BillName: this.BillName,
				BarCode: barcode,
				Model: Model,
				StoreID: this.SelectOutStoreObj.StoreID
			};
			var that = this;
			Api.GetBarcodeGoodsMessageModel(data, function(res) {
				console.log(res.data.ResultMsg);
				that.searchKey = "";
				// Api.showTip(res.data.ResultMsg);
				if (res.data.ResultMsg != '') {
					if (res.data.ResultMsg.length == 0) {
						uni.hideLoading();
						Api.showTip("查无数据");
						that.isSearch = false;
						return;
					}
					res.data.ResultMsg.forEach((item, index) => {
						if (res.data.ResultMsg[index].Goods_Image_Path1 == "") {
							res.data.ResultMsg[index].Goods_Image_Path1 = that.unLoadimg
							// console.log("进来了");
						} else {
							console.log("----进了了");
							res.data.ResultMsg[index].Goods_Image_Path1 = that.allConstUrl + res.data.ResultMsg[index].Goods_Image_Path1;
							// res.data.ResultMsg[index].Goods_Image_Path1 = tempUrl;
							// console.log(tempUrl);
						}
					})
					if (flag) {
						uni.hideLoading();
						that.scanGoodList = that.pullBarCodeGoods(res).data.ResultMsg;
						
						if (that.scanGoodList.length == 1) {
							that.selectGoodsList(0);
						} else {
							if (that.scanGoodList.length > 0) {
								that.modalName = "StoreScanGoodModal";
								that.isSearch = false;
							}

						}
						// uni.showLoading({
						// 	title: "加载中..",
						// 	mask: false
						// })
						// that.tempScanGoodList = that.pullBarCodeGoods(res).data.ResultMsg;
						// that.tempScanGoodList.forEach((item, index) => {
						// 	that.XH_Get_PriceFollowMessage(item, index, function(item, i) {
						// 		that.tempScanGoodList[i].Price = item;
						// 		that.tempScanGoodList[i].DiscountPrice = that.DiscountPrice(that.tempScanGoodList[i]);
						// 		that.tempScanGoodList[i].Amount = that.Amount(that.tempScanGoodList[i]);
						// 		// priceItem.Price = that.PriceList[0].Price;
						// 		console.log(item);
						// 	}, true);
						// });
					} else {
						// that.scanGoodList = res.data.ResultMsg;
						// let NewGoodListTemp = that.OrderGoodsList;
						// uni.showLoading({
						// 	title: "加载中..",
						// 	mask: false
						// })
						res = that.pullBarCodeGoods(res).data.ResultMsg;
						let resultList = [];
						resultList.push(res[0]);
						// console.log(resultList);
						that.pullGoodsInfo(resultList);
						// that.pullGoodsInfo(that.pullBarCodeGoods(res).data.ResultMsg);
					}
					that.searchKey = "";
				} else if (res.data.ResultMsg == "") {
					Api.showTip("查无数据");
					that.isSearch = false;
					uni.hideLoading();
				} else if (res.data.ErrorMsg == "获取登录信息失败") {
					uni.hideLoading();
					that.isSearch = false;
				} else {
					uni.hideLoading();
					that.isSearch = false;
				}
			})
		},
		pullBarCodeGoods(res) {
			var that = this;
			res.data.ResultMsg.forEach((item, index) => {
				res.data.ResultMsg[index].Qty = 1;
				let result = rules.ruleFinalRes(that.SeparateIsEnable, that.barCodeRelus, that.barRulesList, res, that.searchKey,
					index);
				res = result.result;
				if (!result.isChange) {
					res.data.ResultMsg[index].Price = res.data.ResultMsg[index].Price;
					// else{
					// 	res.data.ResultMsg[index].Price = res.data.ResultMsg[index].SalePrice;
					// }
				}
				// res.data.ResultMsg[index].Qty = 1;
				res.data.ResultMsg[index].Discount = 100;
				res.data.ResultMsg[index].Tax = 0;
				res.data.ResultMsg[index].Remark = "";
				res.data.ResultMsg[index].GoodsStorm = 0;
				// res.data.ResultMsg[index].Price = res.data.ResultMsg[index].PFPrice;
				res.data.ResultMsg[index].barcode = res.data.ResultMsg[index].BarCode;
				res.data.ResultMsg[index].URate = res.data.ResultMsg[index].urate;
				res.data.ResultMsg[index].StoreID = that.SelectOutStoreObj.StoreID;
				res.data.ResultMsg[index].StoreID2 = that.SelectInStoreObj.StoreID == "" ? 0 : that.SelectInStoreObj.StoreID;
				res.data.ResultMsg[index].stockqty = Math.round(res.data.ResultMsg[index].stockqty * 100) / 100;
				res.data.ResultMsg[index].PFPrice = Math.round(res.data.ResultMsg[index].PFPrice * 100) / 100;
				res.data.ResultMsg[index].ProductionDate = "";
				res.data.ResultMsg[index].validityDate = "";
				res.data.ResultMsg[index].BatchNo = "";
				res.data.ResultMsg[index].IsGift = 0;
				// if (res.data.ResultMsg[index].Goods_Image_Path1 == "") {
				// 	res.data.ResultMsg[index].Goods_Image_Path1 = that.unLoadimg
				// 	// console.log("进来了");
				// } else {
				// 	res.data.ResultMsg[index].Goods_Image_Path1 = that.allConstUrl + res.data.ResultMsg[index].Goods_Image_Path1;
				// }
				res.data.ResultMsg[index].DiscountPrice = that.DiscountPrice(res.data.ResultMsg[index]);
				res.data.ResultMsg[index].Amount = that.Amount(res.data.ResultMsg[index]);
			});
			return res;
		},
		//移除
		removeItem($index) {
			//删除操作存储未被删除的数据
			var newGoodList = [];
			this.OrderGoodsList.forEach((item, index) => {
				if (index != $index) {
					newGoodList.push(item);
				}
			});
			this.OrderGoodsList = newGoodList;
		},
		//获取更多商品信息
		lookGoodsInfo(index) {
			if (this.selectLookMore == index) {
				this.selectLookMore = -1;
			} else {
				this.selectLookMore = index;
			}
		},
		//修改商品信息
		changeInfo(e) {
			this.AddListens();
			let index = e.currentTarget.detail.changeIndex;
			uni.setStorageSync("ChangeGoodData", JSON.stringify(this.OrderGoodsList[index]));
			uni.navigateTo({
				url: "../goodListRkCk/selectGoodInfo?selectIndex=" +
					index + "&orderType=" + this.BillType + "&ClientID=" + this.SelectClientObj.ClientID
			});
		},
		//获取业务员列表
		GetOperatorMessage(Filter = "") {
			let data = {
				Filter: Filter
			}
			this.picker1 = [];
			var that = this;
			Api.GetOperatorMessage(data, function(res) {
				if (res.state) {
					if (res.data.ErrorMsg == "获取登录信息失败") {
						Api.showTip("登录超时");
					} else if (res.data.ErrorMsg != "") {
						Api.showTip(res.data.ErrorMsg);
					} else {
						let responseData = res.data.ResultMsg;
						if (Filter != "") {
							that.TempOptionList = responseData;
						} else {
							that.OperatorList = responseData;
							that.TempOptionList = responseData;
						}

					}
				} else {

				}
			});
		},
		//增加商品事件监听
		AddListen() {
			var _this = this;
			//当前选择的商品的临时列表
			var NewGoodListTemp = this.OrderGoodsList;
			this.$eventHub.$on('fires', function(data) {
				// let GoodsItem = JSON.parse(data);
				// GoodsItem.forEach((item, index) => {
				// 	if (!_this.IsInOrderList(item).isIn) {
				// 		NewGoodListTemp.push(item);
				// 	}
				// });
				// this.OrderGoodsList = NewGoodListTemp;
				let GoodsItem = JSON.parse(data);
				// console.log(_this.OrderGoodsList);
				uni.showLoading({
					title: "加载中..",
					mask: false
				})
				_this.pullGoodsInfo(GoodsItem);
				_this.$eventHub.$off('fires');
			});
		},
		//判断当前增加的商品是否存在
		IsInOrderList(item) {
			if (item.BatchNo == "" && item.IsBatch) {
				item.isUnAdd = true;
				return item;
			}
			for (var i = 0; i < this.OrderGoodsList.length; i++) {
				if (this.cgSettingLocation.onlyAddNum[0].state) {
					if (this.OrderGoodsList[i].GoodsID == item.GoodsID && this.OrderGoodsList[i].Qty > 0) {
						item.isIn = true;
						this.OrderGoodsList[i].Qty = parseFloat(this.OrderGoodsList[i].Qty) + parseFloat(item.Qty);
						item.Price = this.OrderGoodsList[i].Price;
						item.Discount = this.OrderGoodsList[i].Discount;
						item.Tax = this.OrderGoodsList[i].Tax;
						this.OrderGoodsList[i].Amount += this.getOnlyNumAmount(item);
						return item;
					}
				} else {
					// console.log(this.OrderGoodsList[i].UnitID,item.UnitID);
					// console.log(this.OrderGoodsList[i].urate,item.urate);
					// console.log(this.OrderGoodsList[i].Price,item.Price);
					// console.log(this.OrderGoodsList[i].UnitID,item.UnitID);
					// console.log(this.OrderGoodsList[i].StoreID,item.StoreID);
					// console.log(this.OrderGoodsList[i].IsGift,item.IsGift);
					// console.log(this.OrderGoodsList[i].validityDate,item.validityDate);
					// console.log(this.OrderGoodsList[i].ProductionDate,item.ProductionDate);
					// console.log(this.OrderGoodsList[i].Tax,item.Tax);
					// console.log(this.OrderGoodsList[i].Discount,item.Discount);
					// console.log(this.OrderGoodsList[i].StoreID,item.StoreID);
					// console.log(this.OrderGoodsList[i].StoreID2,item.StoreID2);
					if (this.OrderGoodsList[i].GoodsID == item.GoodsID && this.OrderGoodsList[i].UnitID == item.UnitID &&
						parseFloat(this.OrderGoodsList[i].urate) == parseFloat(item.urate) && parseFloat(this.OrderGoodsList[i].Price) ==
						parseFloat(item.Price) && this.OrderGoodsList[i]
						.StoreID == item.StoreID && item.IsGift == this.OrderGoodsList[i].IsGift &&
						this.OrderGoodsList[i].StoreID2 == item.StoreID2 && this.OrderGoodsList[i].ProductionDate == item.ProductionDate &&
						this.OrderGoodsList[i].validityDate == item.validityDate &&
						parseFloat(this.OrderGoodsList[i].Tax) == parseFloat(item.Tax) && parseFloat(this.OrderGoodsList[i].Discount) ==
						parseFloat(item.Discount) && this.OrderGoodsList[i].Qty > 0 && this.OrderGoodsList[i].BatchNo == item.BatchNo
					) {
						item.isIn = true;
						this.OrderGoodsList[i].Qty = parseFloat(this.OrderGoodsList[i].Qty) + parseFloat(item.Qty);
						this.OrderGoodsList[i].Remark = item.Remark;
						this.OrderGoodsList[i].Amount += parseFloat(item.Amount);
						return item;
					}
				}

			}
			item.isIn = false;
			return item;
		},
		getOnlyNumAmount(item) {
			return parseFloat(item.Price) * parseFloat(item.Qty) * (parseFloat(item.Discount) / 100) * (1 + parseFloat(
				item.Tax) / 100); // return  PFPrice;

		},
		//修改还是新增单据
		isChangeOrder() {
			//如果新增
			if (this.isChange) {
				this.Change_Bill_Order();

			} else {
				this.GetNewOrderNo(true);
			}
		},
		//商品修改事件监听
		AddListens() {
			var _this = this;
			this.$eventHub.$on('fireData', function(data) {
				// let NewGoodInfo = JSON.parse(data.NewGoodInfo);
				// _this.OrderGoodsList[data.index].Tax = parseFloat(NewGoodInfo.Tax);
				// _this.OrderGoodsList[data.index].StoreID = NewGoodInfo.StoreID;
				// _this.OrderGoodsList[data.index].Qty = parseFloat(NewGoodInfo.Qty);
				// _this.OrderGoodsList[data.index].BatchNo = NewGoodInfo.BatchNo;
				// _this.OrderGoodsList[data.index].ProductionDate = NewGoodInfo.ProductionDate;
				// _this.OrderGoodsList[data.index].validityDate = NewGoodInfo.validityDate;
				// _this.OrderGoodsList[data.index].StoreID = NewGoodInfo.StoreID;
				// _this.OrderGoodsList[data.index].UnitName = NewGoodInfo.UnitName;
				// _this.OrderGoodsList[data.index].urate = NewGoodInfo.urate;
				// _this.OrderGoodsList[data.index].UnitID = NewGoodInfo.UnitID;
				// _this.OrderGoodsList[data.index].Price = NewGoodInfo.Price;
				// _this.selectLookMore = -1;
				let NewGoodInfo = JSON.parse(data.NewGoodInfo);
				_this.OrderGoodsList[data.index] = NewGoodInfo;
				let OrderGoodsList = Object.assign([], _this.OrderGoodsList);
				_this.pullBlissfulGoods(data.index, OrderGoodsList);
				// _this.OrderGoodsList = OrderGoodsList;
				_this.$eventHub.$off('fireData');
			});
		},
		//相同的参数商品合并
		pullBlissfulGoods(index, OrderGoodsList) {
			let item = OrderGoodsList[index];
			OrderGoodsList.forEach(($item, $index) => {
				if ($index != index) {
					if ($item.GoodsID == item.GoodsID && $item.UnitID == item.UnitID &&
						parseFloat($item.urate) == parseFloat(item.urate) && parseFloat($item.Price) ==
						parseFloat(item.Price) && $item
						.StoreID == item.StoreID && item.IsGift == $item.IsGift &&
						$item.StoreID2 == item.StoreID2 && $item.ProductionDate == item.ProductionDate &&
						$item.validityDate == item.validityDate &&
						parseFloat($item.Tax) == parseFloat(item.Tax) && parseFloat($item.Discount) ==
						parseFloat(item.Discount) && $item.Qty > 0 && $item.BatchNo == item.BatchNo
					) {
						OrderGoodsList[index].Qty = parseFloat(OrderGoodsList[index].Qty) + parseFloat($item.Qty);
						OrderGoodsList[index].Remark = $item.Remark;
						OrderGoodsList[index].Amount = OrderGoodsList[index].Amount + parseFloat($item.Amount);
						$item.Remark = "";
						$item.Amount = "";
						$item.Qty = 0;
					}
				}
			});
			this.OrderGoodsList = Object.assign([], OrderGoodsList);
			// this.OrderGoodsList = OrderGoodsList;
		},
		//获取仓库
		GetStoreMessage(Filter = "", isIntOut = 2) {
			let data = {
				Filter: Filter
			}
			var that = this;
			Api.GetStoreMessage(data, function(res) {
				if (res.state) {
					if (res.data.ErrorMsg == "获取登录信息失败") {
						Api.showTip("登录超时");
					} else if (res.data.ErrorMsg != "") {
						Api.showTip(res.data.ErrorMsg);
					} else {
						let responseData = res.data.ResultMsg;
						// that.StoreList = res.data.ResultMsg;
						if (Filter != "") {
							if (isIntOut == 0) {
								that.TempStoreInList = res.data.ResultMsg;
							} else if (isIntOut == 1) {
								that.TempStoreOutList = res.data.ResultMsg;
							} else {
								that.TempStoreInList = res.data.ResultMsg;
								that.TempStoreOutList = res.data.ResultMsg;
							}
						} else {
							if (isIntOut == 0) {
								that.StoreInList = res.data.ResultMsg;
							} else if (isIntOut == 1) {
								that.StoreOutList = res.data.ResultMsg;
							} else {
								that.StoreInList = res.data.ResultMsg;
								that.StoreOutList = res.data.ResultMsg;
								that.TempStoreInList = res.data.ResultMsg;
								that.TempStoreOutList = res.data.ResultMsg;
							}
						}

					}
				} else {

				}
			});
		},
		//点击获取单号
		GetNewOrderNo(isPull) {
			this.getBillTime();
			if (!isPull) {
				this.defaultSetting();
			}
			if (this.isUserRoot.IsBill_AddNew == "") {
				Api.showTip("无新增权限");
				return;
			}
			let data = {
				BillType: this.BillType,
				IsAdd: isPull ? 1 : 0,
				BillDate: this.BillDate
			};
			var that = this;
			Api.NewOrderNo(data, function(res) {
				if (res.state) {
					if (res.data.ErrorMsg == "获取登录信息失败") {
						Api.showTip("登录超时");
					} else if (res.data.ErrorMsg != "") {
						Api.showTip(res.data.ErrorMsg);
					} else {
						that.BillNo = res.data.ResultMsg.BillNo
						if (isPull) {
							that.AddBillOrder();
						}
					}
				} else {

				}
			});
		},
		tabSelect(e) {
			this.TabCur = e.currentTarget.dataset.id;
			console.log(22)
			this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60
		},
		PickerChange(e) {
			console.log(e)
			if (e.detail.value == -1) {
				this.index = 0
			} else {
				this.index = e.detail.value
			}
			// this.index = e.detail.value
		},
		PickerChange1(e) {
			console.log(e)
			if (e.detail.value == -1) {
				this.index1 = 0
			} else {
				this.index1 = e.detail.value
			}
			// this.index1 = e.detail.value
		},
		PickerChange2(e) {
			console.log(e)
			if (e.detail.value == -1) {
				this.index2 = 0;
				this.pcChildName = this.StoreList[0].BranchName;
			} else {
				this.index2 = e.detail.value;
				this.pcChildName = this.StoreList[e.detail.value].BranchName;
			}
			// this.index2 = e.detail.value;
			// this.pcChildName = this.StoreList[e.detail.value].BranchName;
		},
		PickerChange3(e) {
			if (e.detail.value == -1) {
				this.index3 = 0;
				this.NowSelectGoods.StoreID = this.StoreList[0].StoreID;
			} else {
				this.index3 = e.detail.value;
				this.NowSelectGoods.StoreID = this.StoreList[e.detail.value].StoreID;
			}
			// this.index3 = e.detail.value;
			// this.NowSelectGoods.StoreID = this.StoreList[e.detail.value];
		},
		xiala(e) {
			var i = e.currentTarget.dataset.findex;
			console.log(i)

		},
		open() {
			this.$refs.calendar.open();
		},
		open1() {
			this.$refs.calendar1.open();
		},
		open2() {
			this.$refs.calendar2.open();
		},
		confirm(e) {
			// var fulldate = e.detail.fulldate
			// console.log(e.detail.fulldate);
			console.log(e)
			this.BillDate = e.fulldate;
		},
		confirm1(e) {
			// var fulldate = e.detail.fulldate
			// console.log(e.detail.fulldate);
			console.log(e)
			this.ProductionDate = e
		},
		confirm2(e) {
			// var fulldate = e.detail.fulldate
			// console.log(e.detail.fulldate);
			console.log(e)
			this.ValidityDate = e
		},
		selectGoodsList(index) {

			this.AddListen();
			this.modalName = "";
			this.isSearch =  true;
			// console.log(this.scanGoodList[index]);
			// return;
			uni.setStorageSync("ChangeGoodData", JSON.stringify(this.scanGoodList[index]));
			uni.navigateTo({
				url: "../goodListRkCk/addScanGood?index=" + index + "&StoreID=" + this.SelectOutStoreObj.StoreID + "&orderType=" +
					this
					.BillType
			});
		},
		gogoodlist() {
			if (this.BillNo == "") {
				Api.showTip("请先创建新单");
				return;
			};

			let title1 = this.BillType == 14 ? '请先选择申请仓库' : '请先选择配入仓库';
			let titleAll = this.BillType == 14 ? '申请仓库与目标仓库不能相同' : '配入仓库与配出仓库不能相同';
			// let title1 = this.BillType == 14 ? '请先选择申请仓库' : '请先选择配入仓库';
			let title2 = this.BillType == 14 ? '请先选择目标仓库' : '请先选择配出仓库';
			if (this.SelectInStoreObj.StoreID == "") {
				uni.showToast({
					title: title1
				});
				return;
			};
			if (this.SelectOutStoreObj.StoreID == "") {
				uni.showToast({
					title: title2
				});
				return;
			};
			// let titleAll = title1+"与"+title2+"不能相同";
			if (this.SelectOutStoreObj.StoreID == this.SelectInStoreObj.StoreID) {
				uni.showToast({
					title: titleAll
				});
				return;
			}
			console.log(this.BillName);
			this.AddListen();
			this.isGetPriceFollowMessage = [];
			var isSelectMore = this.cgSettingLocation.isMoreSelectGood[0].state ? "1" : "0";
			uni.navigateTo({
				url: "../goodListRkCk/goodList?StoreID=" + this.SelectOutStoreObj.StoreID + "&orderType=" + this.BillType +
					"&BillName=" + this.BillName + "&isSelectMore=" + isSelectMore + "&ClientID=" + this.SelectClientObj.ClientID +
					"&StoreID2=" + this.SelectInStoreObj.StoreID
			});
		},
		//显示全部分类
		showType: function() {
			if (this.isShowGoodsType == 0) {
				this.isShowGoodsType = 1;
			} else {
				this.isShowGoodsType = 0;
			}

		},
		//添加商品
		addSelectGoods() {
			if (this.NowSelectGoods.GoodsName == undefined) {
				Api.showTip("请先选择商品");
				return;
			}
			if (this.GoodsQty == "" || this.GoodsQty < 1) {
				Api.showTip("商品数量不能少于1件");
				return;
			}
			if (this.GoodsDiscount == "") {
				Api.showTip("请输入折扣价");
				return;
			}
			if (_this.index3 == -1) {
				Api.showTip("请选择商品仓库");
				return;
			}
			//判断商品是否存在 0否 1 是
			var flag = 0;
			var _this = this;
			// console.log(this.NowSelectGoods);
			console.log(this.GoodsQty);
			console.log(this.GoodsRemark);
			console.log(this.GoodsDiscount);
			this.NowSelectGoods.Qty = this.GoodsQty;
			this.NowSelectGoods.Remark = this.GoodsRemark;
			this.NowSelectGoods.Discount = this.GoodsDiscount;
			this.NowSelectGoods.GoodsStorm = this.GoodsStorm;
			this.NowSelectGoods.Tax = this.Tax;
			this.NowSelectGoods.StoreID = this.StoreList[_this.index3].StoreID;
			console.log(this.NowSelectGoods);
			this.OrderGoodsList.forEach((item, index) => {
				if (item.GoodsID == _this.NowSelectGoods.GoodsID) {
					_this.OrderGoodsList[index].Remark = _this.GoodsRemark;
					_this.OrderGoodsList[index].Qty = _this.GoodsQty;
					_this.OrderGoodsList[index].Discount = _this.GoodsDiscount;
					_this.OrderGoodsList[index].GoodsStorm = _this.GoodsStorm;
					_this.OrderGoodsList[index].Tax = _this.Tax;
					_this.OrderGoodsList[index].StoreID = _this.StoreList[_this.index3].StoreID;
					flag = 1;
				}
			});
			console.log(flag);
			if (flag == 0) {
				this.OrderGoodsList.push(this.NowSelectGoods);
			}
			this.GoodsQty = "";
			this.GoodsRemark = "";
			this.GoodsDiscount = "";
			this.GoodsStorm = "";
			this.Tax = "";
			console.log(this.OrderGoodsList);
			this.NowSelectGoods = {};
			this.isSelectGood = false;
		},
		showModal(e) {
			console.log(1111)
			this.modalName = e.currentTarget.dataset.target
		},
		hideModal(e) {
			this.modalName = null
		},
		choosesunit(e) {
			console.log(e)
			var unit = e.currentTarget.dataset.unit
			this.unitselected = unit
			this.modalName = null
		},
		//计算折扣后的总金额
		compuTaxMoney(item) {
			let PFPrice = parseFloat(item.Price) * parseFloat(item.Qty) * (parseFloat(item.Discount) / 100) * (1 + parseFloat(
				item.Tax) / 100);
			return PFPrice;
		},
		//修改单据
		Change_Bill_Order() {
			this.searchKey = "";
			let title1 = this.BillType == 14 ? '请先选择申请仓库' : '请先选择配入仓库';
			let title2 = this.BillType == 14 ? '请先选择目标仓库' : '请先选择配出仓库';
			if (this.SelectInStoreObj.StoreID == "") {
				uni.showToast({
					title: title1
				});
				return;
			};
			if (this.SelectOutStoreObj.StoreID == "") {
				uni.showToast({
					title: title2
				});
				return;
			};
			var _this = this;
			if (this.BillNo == "") {
				Api.showTip("单号不能为空");
			} else if (this.BillDate == "") {
				Api.showTip("开单时间不能为空")
			} else if (this.SelectOptionsObj.OperatorID == "") {
				Api.showTip("请选择业务员");
			} else if (this.OrderGoodsList.length == 0) {
				Api.showTip("请至少选择一样商品");
			} else {
				var _this = this;

				let CreateName = uni.getStorageSync("UserName");
				let Total = 0;
				this.OrderGoodsList.forEach((item, index) => {
					Total += this.compuTaxMoney(item);
				});
				let CreateID = uni.getStorageSync("UserCode");
				let Save_M_Data_Json = {
					BillNo: _this.BillNo,
					BillTime: _this.BillDate,
					StoreID: _this.SelectOutStoreObj.StoreID,
					StoreID2: _this.SelectInStoreObj.StoreID,
					EmpID: _this.SelectOptionsObj.OperatorID,
					Amount: Total + "",
					CreateID: CreateID,
					CreateName: CreateName,
					Comment: _this.GoodsRemark,
					BankID: "0",
					VIPID: "0",
					CollectAmount: "0",
					NoSmallAmount: "0",
					SourceBillType: "0",
					PayMode: "",
					Int1: "0",
				};
				var Save_D_Data_Json = [];

				this.OrderGoodsList.forEach((item, index) => {
					if (typeof item.StoreID != 'string') {
						item.StoreID = _this.SelectOutStoreObj.StoreID
					}
					if (typeof item.StoreID2 != 'string') {
						item.StoreID2 = _this.SelectInStoreObj.StoreID
					}
					let itemData = {
						BillType: this.BillType,
						GoodsID: item.GoodsID,
						UnitID: item.UnitID,
						URate: item.urate + "",
						Discount: item.Discount + "",
						Tax: item.Tax + "",
						Qty: item.Qty + "",
						Price: item.Price + "",
						Amount: this.compuTaxMoney(item) + "",
						Remark: item.Remark,
						String3: item.BarCode,
						StoreID: item.StoreID,
						StoreID2: item.StoreID2,
						ProductionDate: item.ProductionDate,
						validityDate: item.ValidityDate,
						IsGift: (item.IsGift ? 1 : 0) + "",
						BatchNo: item.BatchNo,
						SourceBillType: 0 + "",
						SourceBillID: 0 + "",
						SourceDetailID: 0 + ""
					};
					Save_D_Data_Json.push(itemData);
				});

				let data = {
					BillType: this.BillType,
					Save_M_Data_Json: JSON.stringify(Save_M_Data_Json),
					Save_D_Data_Json: JSON.stringify(Save_D_Data_Json),
					BillID: this.BillID
				};
				console.log(data);
				Api.Change_Bill(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "获取登录信息失败") {
							Api.showTip("登录超时");
						} else if (res.data.ErrorMsg != "") {
							Api.showTip(res.data.ErrorMsg);
						} else {
							_this.clearAll(true);
							Api.showTip(res.data.ResultMsg);
						}
					} else {

					}
				});
			}
		},
		//修改还是新增单据
		isChangeOrder() {
			//如果新增
			if (this.isChange) {
				this.Change_Bill_Order();

			} else {
				this.GetNewOrderNo(true);
			}
		},
		//提交单据
		AddBillOrder() {
			this.searchKey = "";
			let title1 = this.BillType == 14 ? '请先选择申请仓库' : '请先选择配入仓库';
			let title2 = this.BillType == 14 ? '请先选择目标仓库' : '请先选择配出仓库';
			if (this.SelectInStoreObj.StoreID == "") {
				uni.showToast({
					title: title1
				});
				return;
			};
			if (this.SelectOutStoreObj.StoreID == "") {
				uni.showToast({
					title: title2
				});
				return;
			};
			var _this = this;
			if (this.BillNo == "") {
				Api.showTip("单号不能为空");
			} else if (this.BillDate == "") {
				Api.showTip("开单时间不能为空")
			} else if (this.OrderGoodsList.length == 0) {
				Api.showTip("请至少选择一样商品");
			} else {
				var _this = this;
				let CreateName = uni.getStorageSync("UserName");
				let Total = 0;
				this.OrderGoodsList.forEach((item, index) => {
					Total += this.compuTaxMoney(item);
				});
				let CreateID = uni.getStorageSync("UserCode");
				let Save_M_Data_Json = {
					BillNo: _this.BillNo,
					BillTime: _this.BillDate,
					StoreID: _this.SelectOutStoreObj.StoreID,
					StoreID2: _this.SelectInStoreObj.StoreID,
					EmpID: _this.SelectOptionsObj.OperatorID,
					Amount: Total + "",
					CreateID: CreateID,
					CreateName: CreateName,
					Comment: _this.GoodsRemark,
					BankID: "0",
					VIPID: "0",
					CollectAmount: "0",
					NoSmallAmount: "0",
					SourceBillType: "0",
					PayMode: "",
					Int1: "0",
				};
				var Save_D_Data_Json = [];
				this.OrderGoodsList.forEach((item, index) => {
					if (typeof item.StoreID != 'string') {
						item.StoreID = _this.SelectOutStoreObj.StoreID
					}
					if (typeof item.StoreID2 != 'string') {
						item.StoreID2 = _this.SelectInStoreObj.StoreID
					}
					let itemData = {
						BillType: this.BillType,
						GoodsID: item.GoodsID,
						UnitID: item.UnitID,
						URate: item.URate,
						Discount: item.Discount + "",
						Tax: item.Tax+"",
						Qty: item.Qty + "",
						Price: item.Price + "",
						Amount: this.compuTaxMoney(item) + "",
						Remark: item.Remark,
						String3: item.BarCode,
						StoreID: this.SelectOutStoreObj.StoreID,
						StoreID2: this.SelectInStoreObj.StoreID,
						ProductionDate: item.ProductionDate,
						validityDate: item.validityDate,
						IsGift: (item.IsGift ? 1 : 0) + "",
						BatchNo: item.BatchNo,
						SourceBillType: 0 + "",
						SourceBillID: 0 + "",
						SourceDetailID: 0 + ""
					};
					Save_D_Data_Json.push(itemData);
				});

				let data = {
					BillType: this.BillType,
					Save_M_Data_Json: JSON.stringify(Save_M_Data_Json),
					Save_D_Data_Json: JSON.stringify(Save_D_Data_Json)
				};
				console.log(data);
				Api.AddBill(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "获取登录信息失败") {
							Api.showTip("登录超时");
						} else if (res.data.ErrorMsg != "") {
							Api.showTip(res.data.ErrorMsg);
						} else {
							Api.showTip(res.data.ResultMsg);
							_this.BillID = res.data.BillID;
							if (_this.cgSettingLocation.ycDy[0].state) {
								_this.isPrintOrder(true, res.data.BillID);
							}
							if (_this.cgSettingLocation.ycDy[1].state) {
								_this.isPrintOrder(false, res.data.BillID);
							}


							//如果没有勾选打印
							if (!_this.cgSettingLocation.ycDy[0].state && !_this.cgSettingLocation
								.ycDy[1].state) {
								if (!_this.isBillCheckQx) {
									if (_this.cgSettingLocation.djSh[0].state) {
										_this.isBillCheck(true);
									}
									if (_this.cgSettingLocation.djSh[1].state) {
										_this.isBillCheck(false);
									}
								} else {
									_this.isBillCheck(false);
								}

							}
							_this.clearAll(true);
						}
					} else {

					}
				});

			}
		},
		//打印份数监听
		getPrintNum(e) {
			this.printNum = e.detail.value
		},
		//打印机编号选择事件
		radioChange(e) {
			this.printCode = e.detail.value
		},
		//是否打印单据
		isPrintOrder(type, BillID = "") {
			var that = this;
			if (type) {
				Api.showConfirm("是否打印单据", function(result) {
					if (result) {
						that.PrintOrder(false, BillID);
					} else {
						setTimeout(function() {
							if (!that.isBillCheckQx) {
								if (that.cgSettingLocation.djSh[0].state) {
									that.isBillCheck(true);
								}
								if (that.cgSettingLocation.djSh[1].state) {
									that.isBillCheck(false);
								}
							} else {
								that.isBillCheck(false);
							}
						}, 1000);
					}
				})
			} else {
				that.PrintOrder(false, BillID);
			}
		},
		//是否审核
		isBillCheck(type) {
			var that = this;
			if (type) {
				Api.showConfirm("是否审核单据", function(result) {
					if (result) {
						that.toBillCheck();
					} else {

					}
				})
			} else {
				that.toBillCheck();
			}
		},
		toBillCheck(isInput, BillID = "") {
			var that = this;
			let data = {
				BillType: this.BillType,
				BillID: this.BillID,
				BillName: this.BillName
			};
			Api.Bill_Check(data, function(res) {
				if (res.state) {
					if (res.data.ErrorMsg == '获取登录信息失败') {
						Api.showTip("登录超时!");
					} else if (res.data.ErrorMsg != "") {
						Api.showTip(res.data.ErrorMsg);
					} else {
						// that.isBillCheckSuc[that.isBillCheck] = checkCountList[that.isBillCheck];
						// that.isBillCheck++;
						Api.showTip("审核成功");
					}
				} else {

				}
				// that.toBillCheck(checkCountList, index, countSize);
			})
		},
		PrintOrder(isInput = true, BillID = "") {
			let data = {};
			let Save_M_Data_Json = {};
			if (!isInput) {
				Save_M_Data_Json = {
					Order_Number: this.BillNo,
					BillName: this.BillName,
					Printer: this.CreateName,
					BillID: this.BillID
				};
			} else {
				this.modalNames = null;
				Save_M_Data_Json = {
					Order_Number: this.BillNo,
					BillName: this.BillName,
					Printer: this.CreateName,
					BillID: this.BillID,
					PrintNum: this.printNum + "",
					PrintPCNumber: this.printCode + ""
				};
			}
			data = {
				Save_M_Data_Json: JSON.stringify(Save_M_Data_Json)
			}
			this.printNum = 1;
			this.current = 0;
			this.printCode = 1;
			var _this = this;
			Api.Add_Android_Print(data, function(res) {
				if (res.state) {
					if (res.data.ErrorMsg == '获取登录信息失败') {
						Api.showTip("登录超时");
					} else if (res.data.ErrorMsg != "") {
						Api.showTip(res.data.ErrorMsg);
					} else {
						Api.showTip("已发送打印指令");
						if (!isInput) {
							setTimeout(function() {
								if (_this.cgSettingLocation.djSh[0].state) {
									_this.isBillCheck(true);
								}
								if (_this.cgSettingLocation.djSh[1].state) {
									_this.isBillCheck(false);
								}
							}, 1000);
						}
					}
				}
			})
		},
		ycDy() {
			if (this.isChange) {
				this.$refs.settingOption._data.modalPrintName = "printSetting";
			} else {
				Api.showTip("请先查询单据");
			}
		},
		// //单据审核
		djSh() {
			if (this.isChange) {
				this.isBillCheck();
			} else {
				Api.showTip("请先查询单据");
			}
		}
	}
}
